﻿// 按Id获取对象
var alertINT=1;
function getId(id) {
    return (typeof (id) == "string") ? document.getElementById(id) : id;
}
// 判断是否空字符串
function isEmpty(str) {
    var text = str;
    var len = text.length;
    for (i = 0; i < len; i++) {
        var testEmpty = text.substring(i, i + 1);
        if (testEmpty != " ") {
            return false;
        }
    }
    return true;
}
function gotoPage(context,url){
	var btnArray=[{name:'YES',text:'确 定',def:true},{name:'NO',text:'取 消'}]
	var box=new alertBox(context,null,btnArray,true);
	box.YES.onclick=function(){window.location.href=url;}
	box.NO.onclick=function(){box.hide()}	
}
function checkLogin(url) {
    var context = "没有登录，如果还没有账号，请点击注册！";
    var btnArray = [{ name: 'login', text: '登 录', def: true }, { name: 'register', text: '\u6CE8\u0020\u518C'}]
    var box = new alertBox(context, '\u767B\u5F55\u63D0\u793A', btnArray, true);
    box.login.onclick = function() {
        if(url==null){
            window.location.href = "/login.aspx";
        }
        else{
            window.location.href = "/login.aspx?ReturnUrl=" + url;
        }
        
    }
    box.register.onclick = function() {
        if(url==null){        
            window.location.href = "/register.aspx";
        }
        else{
            window.location.href = "/register.aspx?ReturnUrl=" + url;
        }
    }
} 
function msgBox(context, title) {  //context：内容，title：标题
    var box = new alertBox(context, title, null, true);
    box.OK.onclick = function() { box.hide() }
}
function gotoHistory(content){
    var box = new alertBox(content, null, null, true);
    box.OK.onclick = function() {
        box.hide();window.history.back();
    }
    box.closeBtn.onclick = function() {
        box.hide();
        window.history.back();
    }
    function go(){
        box.hide();
        if(window.history.length) window.history.back();
        else window.location.replace("/");
    }
}
function redirectBox(context,url){//跳转页面提示框
     var box = new alertBox(context, null, null, true);
     box.OK.onclick = function() {box.hide();window.location.href = url; }
     box.closeBtn.onclick = function() {box.hide();window.location.href = url; }
 }
 function redirectPcDeat(context) {//PC版不支持
     var btnArray=[{name:"YES",text:"确 定"},{name:"NO",text:"取 消",def:true}]
     var box = new alertBox(context, null, btnArray, true);
     box.YES.onclick = function() { box.hide(); window.location.href = "/help/"; }
     box.NO.onclick = function() { box.hide();}
 }
function alertBox(context, title, btnArray, hasShade) {
    var _self = this;
	var windowOnScrollFn=window.onscroll;
	
    var _btnArray = btnArray ? btnArray : [{ name: 'OK', text: '\u786E\u0020\u8BA4', def: true}];
	
    var content = document.createElement("div");
    content.className = "alert_content";

    var _title = document.createElement("div");
    _title.innerHTML = title ? title : '\u6E29\u99A8\u63D0\u793A';
    _title.className = "alert_title";
    content.appendChild(_title);

    var closeBtn = document.createElement("input");
    closeBtn.type = "button";
    closeBtn.className = "alert_closeBtn";
    content.appendChild(closeBtn);
    closeBtn.onclick = function() { _self.hide() };
	_self.closeBtn=closeBtn;
	
    var _context = document.createElement("div");
    _context.innerHTML = context ? context : '';
    _context.className = "alert_context";
    content.appendChild(_context);

    var btnContent = document.createElement("div");

    btnContent.className = "alert_btnContent";

    for (var i = 0; i < _btnArray.length; i++) {
        var btn = document.createElement("input");
        btn.type = "button";
        btn.value = _btnArray[i].text;
        if (_btnArray[i].def == true) {
            btn.className = "alert_defaultBtn";
            eval("_self.defBtn=btn");
        }
        eval("_self." + _btnArray[i].name + "=btn");
        btnContent.appendChild(btn);
    }
    content.appendChild(btnContent);

    var shade = null;
    if (hasShade == true) {
        shade = document.createElement("div");
        shade.className = "alert_shade";
        var height = document.body ? document.body.scrollHeight : 480;
        var width = document.body ? document.body.scrollWidth : 320;
        shade.style.height = document.documentElement.scrollHeight + "px";
        shade.style.width = document.documentElement.scrollWidth + "px";
        shade.appendChild(content);
    }
    else {
        shade = content;
    }

    this.hide = function() {
		document.body.removeChild(shade); 
		window.onscroll=windowOnScrollFn;
	}
	this.show = function() {
	    content.style.top = document.documentElement.scrollTop + 100 + "px";
	    content.style.left = document.documentElement.scrollLeft + 17 + "px";
	    if (navigator.userAgent.indexOf('Safari') != -1) {
	        content.style.top = window.scrollY + 100 + "px";
	        content.style.left = window.scrollX + 17 + "px";
	    }
	    if (document.body != null)
	    document.body.appendChild(shade);
	    _self.defBtn.focus();
	};

    this.show();
    return this;
} 
function preLoadImg() {
    var urlArray = ["/images/l00401_03.png",
				  "/images/l0041_01.jpg",
				  "/images/l004_06_03.jpg",
				  "/images/l004_06_05.jpg",
				  "/images/alert_shade.png"];
				  
	var menuImage=["/images/menu/icochat.png",
	               "/images/menu/icoclient.png",
	               "/images/menu/icofriend.png",
	               "/images/menu/icogame.png",
	               "/images/menu/icoindex.png",
	               "/images/menu/icomanage.png",
	               "/images/menu/icomlt.png",
	               "/images/menu/icoout.png",
	               "/images/menu/icouser.png",
	               "/images/menu/linebg.gif",
	               "/images/menu/lineonbg.gif",
	               "/images/menu/makbg.png",
	               "/images/menu/menufrimebg.gif"];
	               
	urlArray=urlArray.concat(menuImage);
    for (var i = 0; i < urlArray.length; i++) {
        var img = new Image();
        img.src = urlArray[i];
    }
} 
function include_js(file,callback) {
    var _doc = document.getElementsByTagName('head')[0];
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');    
    js.setAttribute('src', file);
    _doc.appendChild(js);    
    if (!/*@cc_on!@*/0) { //if not IE        //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload   
        js.onload = function () {if(typeof(callback)=="function") callback();}
    }
    else {        //IE6、IE7 support js.onreadystatechange        
        js.onreadystatechange = function () {
                                   if (js.readyState == 'loaded' || js.readyState == 'complete'){
                                        if(typeof(callback)=="function") callback();     
                                   }                                            
                                }   
    }   
    return false;
}
function addGoogleMapApi(functionName){ //调用此函数可向服务器提交本地地址数据
	var script=document.createElement("script");
	script.type = "text/javascript";
	script.src="http://www.google.cn/jsapi?sensor=true&key=" +  googleMapKey  + "&callback=" + functionName;
	document.getElementsByTagName("head")[0].appendChild(script);	
}
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" + escape(value) +
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/"
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
}
function getQueryString(paras){
    var url = window.location.search;      
    var paraString = window.location.search.substr(1).split("&");      
    var paraObj = {}      
    for (i=0; j=paraString[i]; i++){      
        paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);      
    }      
    var returnValue = paraObj[paras.toLowerCase()];      
    if(typeof(returnValue)=="undefined"){      
        return "";      
    }
    else{      
        return returnValue;      
    }
}
// 判断是否空字符串
String.prototype.isEmpty = function() {
    if(this.replace(/(^\s*)|(\s*$)/g, "").length) return false;
    else return true;
}

//window.onerror=function (msg,url,l){
//	var txt="this Page hava a error \r\n\r\n";
//	txt+="errorMsg:" + msg + "\r\n";
//	txt+="URL: " + url + "\r\n";
//	txt+="row:" + l + "\r\n";
//	alert(txt);
//	//return true;
//}

//document.documentElement.oncontextmenu=function(){return false}
var tmpLoad010518=window.onload;
window.onload=function(){
    if(typeof(tmpLoad010518)=="function") tmpLoad010518();
    if(document.getElementById("menuBox")!=null){   
        var menuBtn=getId("header_btnMenuBox")
        if(menuBtn!=null && typeof(menuBtn)!="undefined"){
            var menuBox=getId("menuBox");
            menuBtn.onclick=function(){
                if(menuBox.style.display=="block") menuBox.style.display="none";
                else{
                    menuBox.style.display="block";
                    menuBox.style.height=document.body.scrollHeight + "px"
                }
		    }
           menuBox.onclick=function(){menuBox.style.display="none"};        
        }
    }

	window.scrollTo(0,1);
	window.setTimeout(preLoadImg,1);
}

function isPcSystem(){
    var userAgentArray = ["symbian", "symbos", "iphone", "blackberry", "android", "blueberry", "windows mobile", "windows phone", "mobile safari", "mobile"];
    var pcSystem=['Win32','MacPPC','Linuxi586'];
    var userAgent=window.navigator.userAgent.toLowerCase();
    
    for(var i=0;i<userAgentArray.length;i++){
        if (userAgent.indexOf(userAgentArray[i]) != -1) {
            return false;
        }
    }
    return true;
}
function historyback(){
    history.back();
}